package alp.starcode.sanping.user.controller;

import alp.starcode.common.web.result.Result;
import alp.starcode.sanping.user.service.LoginService;
import io.swagger.annotations.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * TODO
 *
 * @author wujie
 * @date 2024/3/14 23:44
 */
@Api(tags = {"登录相关接口"})
@RestController
@Validated
public class LoginController {
    @Resource
    private LoginService loginService;

    public LoginController() {
    }

    @PostMapping({"login.do"})
    @ApiOperation("账号密码登录")
    @ApiImplicitParams({@ApiImplicitParam(value = "用户名",
            name = "loginName",
            dataType = "String",
            paramType = "query",
            required = true), @ApiImplicitParam(value = "用户密码",
            name = "loginPwd",
            dataType = "String",
            paramType = "query",
            required = true
    ), @ApiImplicitParam(value = "验证码",
            name = "captcha",
            dataType = "String",
            paramType = "query",
            required = false
    )})
    @ApiOperationSupport(
            order = 10
    )
    public Result<Object> login(String loginName, String loginPwd, String captcha, HttpServletRequest request, HttpServletResponse response) {
        return Result.success(loginService.login(loginName, loginPwd, captcha, request, response));
    }

}
